package game.renderer.Denis;

import java.awt.Color;
import java.awt.Graphics;

import game.classes.gameField.gameArea;
import game.classes.gameField.gamePlayer;
import game.data.implement.gameImageData;
import game.enums.Direction;

public class GameRenderer {

	final static int MAXX = 16;
	final static int MAXY = 8;
	
	MyJFrame myFrame;
	gameArea myArea;
	gameImageData myImages;
	gamePlayer myPlayer;
	
	public GameRenderer(MyJFrame frame, gameImageData iData, gameArea ga, gamePlayer player) {
		myFrame = frame;
		myImages = iData;
		myArea = ga;
		myPlayer = player;
	}

	public void paint(String fps) {
    	Graphics bg = myFrame.getPaintImage().getGraphics();
    	bg.setColor(Color.black);
    	bg.fillRect(0, 0, MAXX * 64 + 40, MAXY * 64 + 60);
    	for (int i = 0; i < myArea.getMaxX(); i++) {
        	for (int j = 0; j < myArea.getMaxY(); j++) {
            	bg.drawImage(myImages.getImageData()[IndexResolver.getFieldIndex(myArea.getTileAtPos(i, j).getID())], 20+i*64, 40+j*64, 64, 64, null);
            	bg.drawImage(myImages.getImageData()[IndexResolver.getBlockIndex(myArea.getBlockAtPos(i, j).getBlockID())], 20+i*64, 40+j*64, 64, 64, null);
            	if (myPlayer.getX() == i && myPlayer.getY() == j) {
            		bg.drawImage(myImages.getImageData()[IndexResolver.getPlayerIndex(myPlayer.getDirection(), myPlayer.getState())], 20+i*64, 40+j*64, 64, 64, null);
            	}
        	}
    	}
    	bg.setColor(Color.WHITE);
    	
    	bg.drawString(fps,100,100);
	}

}
